function matrix = rot_matrix(dir, angle)
%%% This function takes the direction of the rotation (e.g. x, y or z axes)
%%% and creates a 4x4 rotation matrix at a given angle

if dir == 'x' 
    matrix = [1 0 0 0; 0 cos(angle) -sin(angle) 0; 0 sin(angle) cos(angle) 0; 0 0 0 1];
elseif dir == 'y' 
    matrix = [cos(angle) 0 sin(angle) 0; 0 1 0 0; -sin(angle) 0 cos(angle) 0; 0 0 0 1];
elseif dir == 'z' 
    matrix = [cos(angle) -sin(angle) 0 0; sin(angle) cos(angle) 0 0; 0 0 1 0; 0 0 0 1];
else
    error('Please enter x, y or z in the first argument');
end